﻿using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp;

namespace mozhi.smarterp.Finance.Basedatas
{
    public class BaseDataAggregateRootBase : AggregateRootBase<Guid>
    {
        public virtual string Code { protected set; get; }

        public virtual string Name { protected set; get; }

        protected BaseDataAggregateRootBase()
        {

        }

        public BaseDataAggregateRootBase(Guid id, string code, string name, bool activate = true)
        {
            Id = id;
            Code = code;
            Name = name;
            this.Activated = activate;
            Validate();
        }

        public void Change(string code, string name , bool activated)
        {
            Code = code;
            Name = name;
            Activated = activated;

            Validate();
        }

        protected virtual void Validate()
        {
            if (Code.IsNullOrEmpty())
                throw new UserFriendlyException("编码不能为空");

            if (Name.IsNullOrEmpty())
                throw new UserFriendlyException("名称不能为空");
        }
    }
}
